package edu.hawaii.myisern.xml;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import junit.framework.TestCase;
import org.junit.Test; //import com.meterware.httpunit.WebConversation;
//import com.meterware.httpunit.WebLink;
//import com.meterware.httpunit.WebResponse;
//import edu.hawaii.myisern.example.MyIsernXmlLoader;
import edu.hawaii.myisern.collaborations.jaxb.CollaboratingOrganizations;
import edu.hawaii.myisern.collaborations.jaxb.Collaboration;
import edu.hawaii.myisern.collaborations.jaxb.CollaborationTypes;
import edu.hawaii.myisern.collaborations.jaxb.OutcomeTypes;
import edu.hawaii.myisern.organizations.jaxb.AffiliatedResearchers;
import edu.hawaii.myisern.organizations.jaxb.Organization;
import edu.hawaii.myisern.organizations.jaxb.ResearchKeywords;
import edu.hawaii.myisern.researchers.jaxb.Researcher;

//import edu.hawaii.myisern.example.MyIsernXmlLoader;

/**
 * Demonstrates that the sample code is working.
 * 
 * @author Philip Johnson
 * @author Marcius Bagwan
 * @author Sonwright Gomez
 * @author John Hauge
 */
public class TestMyIsernXmlLoader extends TestCase {
  /**
   * Tests the Collaboration XML to Java conversion.
   * 
   * @throws Exception If problems occur.
   */
  @Test
  public void testLoader() throws Exception {
    MyIsernXmlLoader loader = new MyIsernXmlLoader();
    assertNotSame("Check collaborations size", 3, loader.getNumCollaborations());
    assertNotSame("Check organizations size", 2, loader.getNumOrganizations());
    assertNotSame("Check researchers size", 3, loader.getNumResearchers());
    assertTrue("Check Collaborations", loader.getCollaborationsXml().contains("<Collaborations>"));
    loader.addCollaboration("testC");
    loader.addOrganization("testO");
    loader.addResearcher("testR");
    loader.addUniqueId("unique Id");
    assertTrue("Check existing collaboration", loader.containsCollaboration("testC"));
    assertTrue("Check existing organization", loader.containsOrganization("testO"));
    assertTrue("Check existing researcher", loader.containsResearcher("testR"));
    assertTrue("Checking unique Id's", loader.containsUniqueId("unique_Id"));
    List<String> tempR = new ArrayList<String>();
    List<String> tempO = new ArrayList<String>();
    List<String> tempC = new ArrayList<String>();
    Set<String> tempUniqueIdList;
    tempR = loader.getListResearchers();
    tempO = loader.getListOrganizations();
    tempC = loader.getListCollaborations();
    tempUniqueIdList = loader.getUniqueIds();
    assertSame("checking list of researchers", tempR, loader.getListResearchers());
    assertSame("checking list of organizations", tempO, loader.getListOrganizations());
    assertSame("checking list of Collaborations", tempC, loader.getListCollaborations());
    assertSame("Checking set of unique ids", tempUniqueIdList, loader.getUniqueIds());
  }

  /**
   * Tests web link validation method.
   * 
   * @throws Exception if problem occurs.
   */
	
  @Test
  public void testisLinkValidMethod() throws Exception {
    MyIsernXmlLoader mixl = new MyIsernXmlLoader();
    assertTrue("known website: http://www.hawaii.edu", 
               mixl.isValidWebLink("http://www.hawaii.edu"));
    assertFalse("fake website: http://myfake.invalid.website", mixl
        .isValidWebLink("http://myfake.invalid.website"));
    assertFalse("no website entered", mixl.isValidWebLink(""));
  }
  
	
	/**
	   * Tests loader.
	   * 
	   * @throws Exception if problem occurs.
	   */
		
	  @Test
	  public void testXmlLoader() throws Exception {
	    
		  MyIsernXmlLoader mixl = new MyIsernXmlLoader();
		  assertNotNull("loader test", mixl);
	    
	  }
	  
	  /**
	   * Tests Organizations.
	   * 
	   * @throws Exception if problem occurs
	   */
	  @Test
	  public void testObjects() throws Exception {
	    Organization org = new Organization();
	    org.setName("name");
	    org.setContact("contact");
	    org.setCountry("country");
	    org.setHomePage("homepage");
	    org.setResearchDescription("description");
	    org.setType("type");
	    AffiliatedResearchers ar = new AffiliatedResearchers();
	    ar.getAffiliatedResearcher().add("ar");
	    org.setAffiliatedResearchers(ar);
	    ResearchKeywords rk = new ResearchKeywords();
	    rk.getResearchKeyword().add("rk");
	    org.setResearchKeywords(rk);
	    assertSame("homepage should be same", "homepage", org.getHomePage());
	    
	    Researcher res = new Researcher();
	    res.setName("name");
	    res.setBioStatement("bio");
	    res.setEmail("email");
	    res.setOrganization("org");
	    res.setPictureLink("url");
	    assertSame("picture link should be same", "url", res.getPictureLink());
	    
	    Collaboration col = new Collaboration();
	    col.setName("value");
	    col.setDescription("description");
	    CollaboratingOrganizations co = new CollaboratingOrganizations();
	    co.getCollaboratingOrganization().add("co");
	    CollaborationTypes ct = new CollaborationTypes();
	    ct.getCollaborationType().add("ct");
	    OutcomeTypes ot = new OutcomeTypes();
	    ot.getOutcomeType().add("ot");
	    col.setCollaborationTypes(ct);
	    col.setOutcomeTypes(ot);
	    col.setCollaboratingOrganizations(co);
	  }
	  

	  
}
